import request from './request';

// 获取主机出租订单列表
export function getHostOrderList(params) {
  return request({
    url: '/api/omm/host-orders/',
    method: 'get',
    params
  });
}

// 获取单个主机出租订单
export function getHostOrder(id) {
  return request({
    url: `/api/omm/host-orders/${id}/`,
    method: 'get'
  });
}

// 新增主机出租订单
export function createHostOrder(data) {
  return request({
    url: '/api/omm/host-orders/',
    method: 'post',
    data
  });
}

// 更新主机出租订单
export function updateHostOrder(id, data) {
  return request({
    url: `/api/omm/host-orders/${id}/`,
    method: 'put',
    data
  });
}

// 删除主机出租订单
export function deleteHostOrder(id) {
  return request({
    url: `/api/omm/host-orders/${id}/`,
    method: 'delete'
  });
}

// 批量删除主机出租订单
export function batchDeleteHostOrders(ids) {
  return request({
    url: '/api/omm/host-orders/batch_delete/',
    method: 'post',
    data: { ids }
  });
}

// 导出主机出租订单数据
export function exportHostOrders(params) {
  return request({
    url: '/api/omm/host-orders/export/',
    method: 'get',
    params,
    responseType: 'blob',
    timeout: 60000 // 60秒超时
  });
}

// 导入主机出租订单数据
export function importRentals(formData) {
  console.log('发送导入请求:', formData);
  return request({
    url: '/api/omm/host-orders/import_data/',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    timeout: 60000 // 60秒超时
  });
}

// 获取主机出租订单导入模板
export function getHostOrderImportTemplate() {
  return request({
    url: '/api/omm/host-orders/import_template/',
    method: 'get',
    responseType: 'blob',
    timeout: 30000 // 30秒超时
  });
}

// 添加别名函数，使前端代码中的 downloadImportTemplate 能正常工作
export function downloadImportTemplate() {
  return getHostOrderImportTemplate();
} 